package com.src;

import java.sql.SQLException;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.codehaus.jettison.json.JSONObject;

@Path("/voteExperience")
public class VoteService {

	@GET
	@Path("/doVote")
	@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
	public String doVote(@QueryParam("type") String type, @QueryParam("experienceID") int expID){
		
		String response = saveVote(type,expID);
		
		return response;
//		
//		Boolean result = null;
//		try {
//			result = DBConnection.saveVote(tag,body,username);
//		} catch (SQLException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		JSONObject obj = new JSONObject();
//		if(result == null || result == false){
//			return true;
//		} else {
//			return false;
//		}
//		
//		return true;
	}

	private String saveVote(String type, int expID) {
		// TODO Auto-generated method stub
		
		Boolean result = null;
		try {
			result = DBConnection.saveVote(expID,type);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		JSONObject obj = new JSONObject();
		if(result == null || result == false){
			return Utitlity.constructJSON("false", "Internal System Error");
		} else {
			return Utitlity.constructJSON("true", "");
		}
	}
	
	
}
